//
//  SoCangViewController.m
//  OurRelaxDemo
//
//  Created by apple on 15/7/1.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "SoCangViewController.h"
#import "DBCenter.h"
#import "SoCangCell.h"
@interface SoCangViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *arr;
@end

@implementation SoCangViewController
-(void)dealloc
{
    [_tableView release];
    [_arr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[SoCangCell class] forCellReuseIdentifier:@"reuse"];
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 30, 30)];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    
    imageview.image = [UIImage imageNamed:@"kong.png"];
    [imageview addGestureRecognizer:tap];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:imageview];
    [imageview release];
    [self.navigationItem.leftBarButtonItem release];
    [tap release];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SoCangCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    cell.model = [self.arr objectAtIndex:indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld", indexPath.row);
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
#pragma mark 抽屉, 可以设置成动画效果
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    
}
#pragma mark 叶面积将出现
- (void)viewWillAppear:(BOOL)animated
{
    self.arr = [NSMutableArray array];
    DBCenter *dataBase = [DBCenter shareInstence];
    [dataBase openDB];
    self.arr = [dataBase selectAll];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
